package com.jilin.library.controller;

import com.jilin.library.entity.BorrowRecord;
import com.jilin.library.service.BorrowRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/borrows")
@CrossOrigin
public class BorrowRecordController {
    @Autowired
    private BorrowRecordService borrowRecordService;
    
    @GetMapping
    public List<BorrowRecord> getAllBorrows() {
        return borrowRecordService.findAll();
    }
    
    @PostMapping
    public BorrowRecord borrowBook(@RequestBody BorrowRecord record) {
        return borrowRecordService.borrowBook(record);
    }
    
    @PutMapping("/{id}/return")
    public int returnBook(@PathVariable Integer id) {
        return borrowRecordService.returnBook(id);
    }
} 